package com.trg.generaltool.service.rabbitmq.route;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.trg.generaltool.util.rabbitmq.RabbitmqUtil;

import java.io.IOException;

/**
 * @ClassName: RouteProvider
 * @Description: 发布/订阅者模式-生产者
 * @Author: tangrg
 * @Date: 2021/7/19 11:39
 * @Version: 1.0
 * @Return:
 **/
public class RouteProvider {

    public static void main(String[] args) throws IOException {
        Connection connect = RabbitmqUtil.getConnect();
        Channel channel = connect.createChannel();
        //通道和交换机进行绑定
        channel.exchangeDeclare("logs_direct", "direct");
        //声明7一个要发送的routing key
        String routKey = "warning";
        channel.basicPublish("logs_direct", routKey, null, ("routing key:" + routKey).getBytes());
        RabbitmqUtil.closeConnect(connect, channel);
    }
}
